<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html><head><title>QHttpPart Class Reference</title><style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }
td.postheader { font-family: sans-serif }
tr.address { font-family: sans-serif }
body { background: #ffffff; color: black; }
</style></head><body><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr /><td align="left" valign="top" width="32"><img align="left" border="0" height="32" src="images/rb-logo.png" width="32" /></td><td width="1">&#160;&#160;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&#160;&#183; <a href="classes.html"><font color="#004faf">All Classes</font></a>&#160;&#183; <a href="modules.html"><font color="#004faf">Modules</font></a></td></table><h1 align="center">QHttpPart Class Reference<br /><sup><sup>[<a href="qtnetwork.html">QtNetwork</a> module]</sup></sup></h1><p>The QHttpPart class holds a body part to be used inside a HTTP
multipart MIME message. <a href="#details">More...</a></p>

<h3>Methods</h3><ul><li><div class="fn" /><b><a href="qhttppart.html#QHttpPart">__init__</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qhttppart.html#QHttpPart-2">__init__</a></b> (<i>self</i>, QHttpPart&#160;<i>other</i>)</li><li><div class="fn" /><b><a href="qhttppart.html#setBody">setBody</a></b> (<i>self</i>, QByteArray&#160;<i>body</i>)</li><li><div class="fn" /><b><a href="qhttppart.html#setBodyDevice">setBodyDevice</a></b> (<i>self</i>, QIODevice&#160;<i>device</i>)</li><li><div class="fn" /><b><a href="qhttppart.html#setHeader">setHeader</a></b> (<i>self</i>, QNetworkRequest.KnownHeaders&#160;<i>header</i>, QVariant&#160;<i>value</i>)</li><li><div class="fn" /><b><a href="qhttppart.html#setRawHeader">setRawHeader</a></b> (<i>self</i>, QByteArray&#160;<i>headerName</i>, QByteArray&#160;<i>headerValue</i>)</li></ul><h3>Special Methods</h3><ul><li><div class="fn" />bool <b><a href="qhttppart.html#__eq__">__eq__</a></b> (<i>self</i>, QHttpPart&#160;<i>other</i>)</li><li><div class="fn" />bool <b><a href="qhttppart.html#__ne__">__ne__</a></b> (<i>self</i>, QHttpPart&#160;<i>other</i>)</li></ul><a name="details" /><hr /><h2>Detailed Description</h2><p>The QHttpPart class holds a body part to be used inside a HTTP
multipart MIME message.</p>
<p>The QHttpPart class holds a body part to be used inside a HTTP
multipart MIME message (which is represented by the <a href="qhttpmultipart.html">QHttpMultiPart</a> class). A QHttpPart
consists of a header block and a data block, which are separated by
each other by two consecutive new lines. An example for one part
would be:</p>
<pre class="cpp">
 Content<span class="operator">-</span>Type: text<span class="operator">/</span>plain
 Content<span class="operator">-</span>Disposition: form<span class="operator">-</span>data; name<span class="operator">=</span><span class="string">"text"</span>

 here goes the body
</pre>
<p>For setting headers, use <a href="qhttppart.html#setHeader">setHeader</a>() and <a href="qhttppart.html#setRawHeader">setRawHeader</a>(), which behave
exactly like <a href="qnetworkrequest.html#setHeader">QNetworkRequest.setHeader</a>()
and <a href="qnetworkrequest.html#setRawHeader">QNetworkRequest.setRawHeader</a>().</p>
<p>For reading small pieces of data, use <a href="qhttppart.html#setBody">setBody</a>(); for larger data blocks like
e.g. images, use <a href="qhttppart.html#setBodyDevice">setBodyDevice</a>(). The latter
method saves memory by not copying the data internally, but reading
directly from the device. This means that the device must be opened
and readable at the moment when the multipart message containing
the body part is sent on the network via <a href="qnetworkaccessmanager.html#post">QNetworkAccessManager.post</a>().</p>
<p>To construct a QHttpPart with a small body, consider the
following snippet (this produces the data shown in the example
above):</p>
<pre class="cpp">
 <span class="type">QHttpPart</span> textPart;
 textPart<span class="operator">.</span><a href="qhttppart.html#setHeader">setHeader</a>(<span class="type"><a href="qnetworkrequest.html">QNetworkRequest</a></span><span class="operator">.</span>ContentTypeHeader<span class="operator">,</span> <span class="type"><a href="qvariant.html">QVariant</a></span>(<span class="string">"text/plain"</span>));
 textPart<span class="operator">.</span><a href="qhttppart.html#setHeader">setHeader</a>(<span class="type"><a href="qnetworkrequest.html">QNetworkRequest</a></span><span class="operator">.</span>ContentDispositionHeader<span class="operator">,</span> <span class="type"><a href="qvariant.html">QVariant</a></span>(<span class="string">"form-data; name=\"text\""</span>));
 textPart<span class="operator">.</span><a href="qhttppart.html#setBody">setBody</a>(<span class="string">"here goes the body"</span>);
</pre>
<p>To construct a QHttpPart reading from a device (e.g. a file),
the following can be applied:</p>
<pre class="cpp">
 <span class="type">QHttpPart</span> imagePart;
 imagePart<span class="operator">.</span><a href="qhttppart.html#setHeader">setHeader</a>(<span class="type"><a href="qnetworkrequest.html">QNetworkRequest</a></span><span class="operator">.</span>ContentTypeHeader<span class="operator">,</span> <span class="type"><a href="qvariant.html">QVariant</a></span>(<span class="string">"image/jpeg"</span>));
 imagePart<span class="operator">.</span><a href="qhttppart.html#setHeader">setHeader</a>(<span class="type"><a href="qnetworkrequest.html">QNetworkRequest</a></span><span class="operator">.</span>ContentDispositionHeader<span class="operator">,</span> <span class="type"><a href="qvariant.html">QVariant</a></span>(<span class="string">"form-data; name=\"image\""</span>));
 imagePart<span class="operator">.</span><a href="qhttppart.html#setRawHeader">setRawHeader</a>(<span class="string">"Content-ID"</span><span class="operator">,</span> <span class="string">"my@content.id"</span>); <span class="comment">// add any headers you like via setRawHeader()</span>
 <span class="type"><a href="qfile.html">QFile</a></span> <span class="operator">*</span>file <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qfile.html">QFile</a></span>(<span class="string">"image.jpg"</span>);
 file<span class="operator">-</span><span class="operator">&gt;</span>open(<span class="type"><a href="qiodevice.html">QIODevice</a></span><span class="operator">.</span>ReadOnly);
 imagePart<span class="operator">.</span><a href="qhttppart.html#setBodyDevice">setBodyDevice</a>(file);
</pre>
<p>Be aware that QHttpPart does not take ownership of the device
when set, so it is the developer's responsibility to destroy it
when it is not needed anymore. A good idea might be to set the
multipart message as parent object for the device, as documented at
the documentation for <a href="qhttpmultipart.html">QHttpMultiPart</a>.</p>
<hr /><h2>Method Documentation</h2><h3 class="fn"><a name="QHttpPart" />QHttpPart.__init__ (<i>self</i>)</h3><p>Constructs an empty <a href="qhttppart.html">QHttpPart</a>
object.</p>


<h3 class="fn"><a name="QHttpPart-2" />QHttpPart.__init__ (<i>self</i>, <a href="qhttppart.html">QHttpPart</a>&#160;<i>other</i>)</h3><p>Creates a copy of <i>other</i>.</p>


<h3 class="fn"><a name="setBody" />QHttpPart.setBody (<i>self</i>, <a href="qbytearray.html">QByteArray</a>&#160;<i>body</i>)</h3><p>Sets the body of this MIME part to <i>body</i>. The body set
with this method will be used unless the device is set via <a href="qhttppart.html#setBodyDevice">setBodyDevice</a>(). For a large
amount of data (e.g. an image), use <a href="qhttppart.html#setBodyDevice">setBodyDevice</a>(), which will not
copy the data internally.</p>
<p><b>See also</b> <a href="qhttppart.html#setBodyDevice">setBodyDevice</a>().</p>


<h3 class="fn"><a name="setBodyDevice" />QHttpPart.setBodyDevice (<i>self</i>, <a href="qiodevice.html">QIODevice</a>&#160;<i>device</i>)</h3><p>Sets the device to read the content from to <i>device</i>. For
large amounts of data this method should be preferred over <a href="qhttppart.html#setBody">setBody</a>(), because the content is not
copied when using this method, but read directly from the device.
<i>device</i> must be open and readable. <a href="qhttppart.html">QHttpPart</a> does not take ownership of
<i>device</i>, i.e. the device must be closed and destroyed if
necessary. if <i>device</i> is sequential (e.g. sockets, but not
files), <a href="qnetworkaccessmanager.html#post">QNetworkAccessManager.post</a>()
should be called after <i>device</i> has emitted finished(). For
unsetting the device and using data set via <a href="qhttppart.html#setBody">setBody</a>(), use "setBodyDevice(0)".</p>
<p><b>See also</b> <a href="qhttppart.html#setBody">setBody</a>()
and <a href="qnetworkaccessmanager.html#post">QNetworkAccessManager.post</a>().</p>


<h3 class="fn"><a name="setHeader" />QHttpPart.setHeader (<i>self</i>, <a href="qnetworkrequest.html#KnownHeaders-enum">QNetworkRequest.KnownHeaders</a>&#160;<i>header</i>, QVariant&#160;<i>value</i>)</h3><p>Sets the value of the known header <i>header</i> to be
<i>value</i>, overriding any previously set headers.</p>
<p><b>See also</b> <a href="qnetworkrequest.html#KnownHeaders-enum">QNetworkRequest.KnownHeaders</a>,
<a href="qhttppart.html#setRawHeader">setRawHeader</a>(), and
<a href="qnetworkrequest.html#setHeader">QNetworkRequest.setHeader</a>().</p>


<h3 class="fn"><a name="setRawHeader" />QHttpPart.setRawHeader (<i>self</i>, <a href="qbytearray.html">QByteArray</a>&#160;<i>headerName</i>, <a href="qbytearray.html">QByteArray</a>&#160;<i>headerValue</i>)</h3><p>Sets the header <i>headerName</i> to be of value
<i>headerValue</i>. If <i>headerName</i> corresponds to a known
header (see <a href="qnetworkrequest.html#KnownHeaders-enum">QNetworkRequest.KnownHeaders</a>),
the raw format will be parsed and the corresponding "cooked" header
will be set as well.</p>
<p>Note: setting the same header twice overrides the previous
setting. To accomplish the behaviour of multiple HTTP headers of
the same name, you should concatenate the two values, separating
them with a comma (",") and set one single raw header.</p>
<p><b>See also</b> <a href="qnetworkrequest.html#KnownHeaders-enum">QNetworkRequest.KnownHeaders</a>,
<a href="qhttppart.html#setHeader">setHeader</a>(), and <a href="qnetworkrequest.html#setRawHeader">QNetworkRequest.setRawHeader</a>().</p>


<h3 class="fn"><a name="__eq__" />bool QHttpPart.__eq__ (<i>self</i>, <a href="qhttppart.html">QHttpPart</a>&#160;<i>other</i>)</h3><h3 class="fn"><a name="__ne__" />bool QHttpPart.__ne__ (<i>self</i>, <a href="qhttppart.html">QHttpPart</a>&#160;<i>other</i>)</h3><address><hr /><div align="center"><table border="0" cellspacing="0" width="100%"><tr class="address"><td align="left" width="25%">PyQt&#160;snapshot-4.9.5-9eb6aac99275 for X11</td><td align="center" width="50%">Copyright &#169; <a href="http://www.riverbankcomputing.com">Riverbank&#160;Computing&#160;Ltd</a> and <a href="http://www.qtsoftware.com">Nokia</a> 2012</td><td align="right" width="25%">Qt&#160;4.8.3</td></tr></table></div></address></body></html>